/*

Author   : chaos

FileName : stl_vector.cpp

Date     : 17/08/17 03:55:51

*/
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;

#define Size 4

template <class T>
void print(vector<T> &);

int main(int argc ,char *argv[])
{
    vector<int> v;

    cout << "Push back 1,6,4 ..." << endl;
    v.push_back(1);
    v.push_back(6);
    v.push_back(4);
    print(v);

    cout << "Insert 9 ..." << endl << "v :";
    v.insert(v.begin(),9);
    print(v);

    cout << "Erase second element ..." << endl << "v :";
    v.erase(v.begin() + 1);
    print(v);

    cout << "Second element :" << v[1] << endl;
    cout << "The Size of Vector : " << v.size() << endl;
    cout << "Maximum size : " << v.max_size() << endl;

    cout << "Using array to initialiize vector ... " << endl
        << "v1 : ";
    int a[Size] = {1,5,3,2};
    vector<int> v1(a,a+Size);
    print(v1);

    cout << "Assgin v1 to v ..." << endl << "v : " ;
    v = v1;
    print(v);


    return 0;
}


template <class T>
void print(vector<T> & pri_con)
{
    if(pri_con.empty()){
        cout << "Container is empty" << endl;
    }
    else{
        typename vector<T>::iterator i;

        for(i = pri_con.begin(); i !=pri_con.end(); i++)
        {
            cout << *i << " ";
        }
        cout << endl;
    }
}
